package com.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.app.R;

public class MenuAdapter extends BaseAdapter {

    String [] list;
    Context context;

    public MenuAdapter(Context context, String[] list){
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.length;
    }

    @Override
    public Object getItem(int position) {
        return list[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if(convertView==null){

            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.menu_item,parent,false);
            holder = new Holder();
            holder.tvName = convertView.findViewById(R.id.tv_name);
            convertView.setTag(holder);
        }else{
            holder = (Holder) convertView.getTag();
        }
        holder.tvName.setText(list[position]);
        return convertView;
    }

    class Holder{
        TextView tvName;
    }

}